package com.lzs.adx.web.modules.job.task;

import com.alibaba.fastjson.JSON;
import com.lzs.adx.web.modules.adx.dto.AccountDTO;
import com.lzs.adx.web.modules.adx.dto.FakerExtend;
import com.lzs.adx.web.modules.adx.service.AccountService;
import com.lzs.adx.web.modules.job.support.FakerFactory;
import com.lzs.adx.web.modules.job.support.faker.AbstractFakerBackStrategy;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 虚拟回传回传的处理
 */
@Component
@Slf4j
public class FackerTask implements ITask{

    @Autowired
    private AccountService accountService;

    @Override
    public void run(String params) {

        //1.查询需要虚拟回传的账户 正常状态的账户
        Map<String,Object> paramsMap=new HashMap<String,Object>();
        paramsMap.put("callType",2);
        paramsMap.put("satus",1);
        List<AccountDTO> list = accountService.list(paramsMap);

        //不同的回传策略类型 执行回传
        for(AccountDTO accountDTO:list){
            //1.1 获取回传策略
            FakerExtend fakerExtend= JSON.parseObject( accountDTO.getFakeExtend(),FakerExtend.class);
            Integer type = fakerExtend.getType();

            //根据不同的策略走不同的回传策略
            AbstractFakerBackStrategy fakerBackStrategy = FakerFactory.getFakerBackStrategy(type);
            fakerBackStrategy.handerFakerBack(accountDTO,fakerExtend);
        }


    }
}
